package com.cyz.admin.controller;

import com.cyz.common.dto.OtcDto;
import com.cyz.admin.service.OtcService;
import com.cyz.common.utils.R;
import com.cyz.common.validated.AddGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(tags = "管理端外部合作课相关接口")
@RestController
@RequestMapping("/otc")
public class OtcController {

    @Autowired
    private OtcService otcService;

    @PreAuthorize("@ps.hasPermission('contant:otc:otc')")
    @ApiOperation(value = "查询外部合作课")
    @GetMapping("/queryOtcs")
    public R queryOtcs(){
        return otcService.queryOtc();
    }

    @PreAuthorize("@ps.hasPermission('contant:otc:otc')")
    @ApiOperation(value = "更新外部合作课")
    @PutMapping("/updateOtc")
    public R updateOtc(@RequestBody OtcDto otcDto){
        return otcService.updateOtc(otcDto);
    }

    @PreAuthorize("@ps.hasPermission('contant:otc:otc')")
    @ApiOperation(value = "增加外部合作课")
    @PostMapping("/addOtc")
    public R addOtc(@Validated(AddGroup.class) @RequestBody OtcDto otcDto){
        return otcService.addOtc(otcDto);
    }

    @PreAuthorize("@ps.hasPermission('contant:otc:otc')")
    @ApiOperation(value = "删除外部合作课")
    @DeleteMapping("/deleteOtcs")
    public R deleteOtcs(Integer[] ids){
        return otcService.deleteOtcs(ids);
    }

}
